﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using FastReport;
using MINERP.BLL.Statistics;
using MINERP.COM;
using MINERP.MODEL.FoundationModel;

namespace MINERP.Statistics.Forms
{
    public partial class FrmOutShopProductStat : Form
    {
        public FrmOutShopProductStat()
        {
            InitializeComponent();
        }
        OutShopBillBLL _bll = new OutShopBillBLL();
        private static FrmOutShopProductStat instance = null;
        public static FrmOutShopProductStat GetInstance
        {
            get
            {
                if (instance == null)
                {
                    instance = new FrmOutShopProductStat();

                }
                return instance;
            }
        }
        private void FrmOutShopProductStat_Load(object sender, EventArgs e)
        {
            comboBoxOutShop.DataSource = _bll.GetShopList();
            comboBoxOutShop.DisplayMember = "OutShopName";
            comboBoxOutShop.ValueMember = "OutShopId";
        }

        private void simpleButtonOK_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                int outShopID = ((OutProcessShop_Info) comboBoxOutShop.SelectedItem).OutShopId;
                //int     productStatus = checkBoxProductStstus.Checked
                //                    ? (int) OutProcessProductStatus.Received
                //                    : (int) OutProcessProductStatus.Outting;
                int payStatus=0;
                int productStatus = 0;
                string productStr = "";
                string payStr = "";
                if (checkBoxPayStatus.Checked)
                {
                    payStatus = (int)OutProcessPayStatus.Complete;
                    payStr = "已付款";
                }
                else
                {
                  payStatus=  (int)OutProcessPayStatus.UnPay;
                  payStr = "未付款";
                }
                if(checkBoxProductStstus.Checked)
                {
                    productStatus = (int)OutProcessProductStatus.Received;
                    productStr = "已收货";
                }
                else
                {
                    productStatus = (int)OutProcessProductStatus.Outting;
                    productStr = "委外中";
                }
                //int payStatus = checkBoxPayStatus.Checked
                //                    ? (int) OutProcessPayStatus.UnPay
                //                    : (int) OutProcessPayStatus.Complete;
               DataSet set= _bll.GetOutShopProduct(outShopID, Convert.ToDateTime(dateEditStartTime.Text),
                                       Convert.ToDateTime(dateEditEndTime.Text), productStatus, payStatus);
               set.WriteXml(@"C:\windows\xmlData\委外商产品.xml", XmlWriteMode.WriteSchema);
               Report report = new Report();
               report.Load(Application.StartupPath + "\\Report\\委外产品统计.frx");
               report.Preview = previewControl1;
               report.SetParameterValue("ParaStartTime", dateEditStartTime.Text);
               report.SetParameterValue("ParaEndTime", dateEditEndTime.Text);
               report.SetParameterValue("ParaProductStatus", productStr);
               report.SetParameterValue("ParaPayStatus", payStr);
               previewControl1.Refresh();
               previewControl1.Show();
               report.Show();
            }
            catch(Exception ex)
            {
                MessageBox.Show("读取数据失败，请稍后再试", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }

        }

        private void FrmOutShopProductStat_FormClosing(object sender, FormClosingEventArgs e)
        {
            instance = null;
        }
    }
}
